var generate = function(rowIndex) {
  // arr[i][j] = arr[i-1][j]+arr[i-1][j-1]
  let arr = []
  for(var i = 0;i<numRows;i++) {
    arr[i] = []
    for(var j = 0;j<=i;j++) {
      if(j==0||j==i) {
        arr[i][j] = 1
      }else {
        arr[i][j] = arr[i-1][j]+arr[i-1][j-1]
      }
    }
  }
  return arr
};  

console.log(generate(3));